export default {
    data() {
        return {
            page: 1,
            limit: 10,
            count: 0,
            // 表格数据
            tableData: [],
            dialogVisible: false,

            balance_money: 0, //未结算金额
            ruleForm: {
                refund_num: '', //结算金额
            },
            rules: {
                refund_num: [{
                    required: true,
                    message: '请输入退款金额',
                    trigger: 'blur'
                }, ],
            },
        }
    },
    /**
     * 进入页面加载
     */
    mounted: function () {
        var that = this;
        //在缓存中获取值
        that.user_name = sessionStorage.getItem("user_name");
        that.user_id = sessionStorage.getItem("user_id");
        that.token = sessionStorage.getItem("access-token");
        if ((!that.token) || (!that.user_id) || (!that.user_name)) {
            that.$router.push('/login');
        }
        that.getList();
    },

    /**
     * 方法
     */
    methods: {
        /**
         * 除去邮轮趣玩的列表
         */
        getList() {
            const that = this;
            that.tableData = [];
            //请求的数据
            const formData = {};
            formData.token = that.token;
            //请求邀请者列表
            that.$http.post(that.adminApi.api_url + "/Operator/operatorlist", formData, {
                emulateJSON: true
            }).then(
                function (res) {
                    // 处理成功的结果
                    if (res.body) {
                        for (var i in res.body.list) {
                            if (res.body.list[i].status === 1) {
                                var status_text = true;
                            } else {
                                var status_text = false;
                            }
                            that.tableData.push({
                                i: i,
                                id: res.body.list[i].id,
                                company: res.body.list[i].company,
                                name: res.body.list[i].name,
                                mobile: res.body.list[i].mobile,
                                create_time: res.body.list[i].create_time,
                                count: res.body.list[i].count,
                                status_text: status_text,
                                last_time: res.body.list[i].last_time,
                                unsettled: res.body.list[i].unsettled != '' ? res.body.list[i].unsettled : '无',
                            });
                        }
                        that.count = res.body.count;
                    }
                },
                function () {
                    // 处理失败的结果
                    that.$message({
                        type: 'error',
                        message: `操作提示: ${ '处理异常' }`
                    });
                });
        },



        /**
         * 下一页
         * @param currentPage
         */
        handleCurrentChange: function (currentPage) {
            var that = this;
            that.page = currentPage;
        },

        /**
         * 添加合作商
         */
        add_operator_list: function () {
            const that = this;
            that.$router.push({
                path: '/operator/add_operator_list'
            })
        },

        /**
         * 修改合作商
         */
        edit: function (e) {
            const that = this;
            that.$router.push({
                path: '/operator/add_operator_list',
                query: {
                    seller_id: e
                }
            })
        },

        /**
         * 关闭弹窗
         */
        handleClose: function () {
            this.dialogVisible = false;
        },

        /**
         * 查看订单
         */
        see_order() {
            this.$router.push('/operatorder/operatorder_list')
        },

        /**
         * 结算按钮
         */
        balance(id, balance_money) {
            this.balance_id = id;
            this.dialogVisible = true;
            this.balance_money = balance_money;
        },

        /**
         * 结算 弹窗 点击确认
         */
        confirm_balance() {
            var that = this;

            var not_balance_money = that.balance_money; //未结算金额
            var refund_num = that.ruleForm.refund_num - 0; //想要结算金额

            if (refund_num > not_balance_money || !Number.isInteger(refund_num)) {
                this.$message.warning('请正确输入金额');
                return;
            }

            //请求的数据
            const formData = {};
            formData.token = that.token;
            formData.seller_id = that.balance_id;
            formData.total_price = that.ruleForm.refund_num;

            // 结算
            that.$http.post(that.adminApi.api_url + "/Publics/settlement", formData, {
                emulateJSON: true
            }).then(function (res) {
                if (res.body.status == 1) that.$message.success('结算成功');
                // 关闭结算对话框
                that.dialogVisible = false;
            })
        },

        /**
         * 跳转到 结算记录
         */
        balance_record() {
            this.$router.push('/operator/balance_record')
        }
    }
}